class Action_Flow
  attr_accessor :actions
  attr_accessor :runing
  attr_accessor :wating
  def initialize
    @actions = []
    @runing = false
  end
  def add_action(item)
    @actions.push(item)
    return item
  end
  def add_action_to_top(item)
    index = 0
    if @actions.size > 0
      for item in @actions
        index += 1
        if item.type == 0
          break
        end
      end
    end
    @actions.insert(index, item)
    str = "insert on " + index.to_s + ", after="
    for item in @actions
      str += GlobalMethods.objToStr(item)
    end
    GlobalMethods.addLog(str)
    return item
  end
  def batch_add_actions(items)
    @actions.concat(items)
  end
  def batch_add_actions_to_top(items)
    index = 0
    if @actions.size > 0
      for item in @actions
        index += 1
        if item.type == 0
          break
        end
      end
    end
    @actions.insert(index, *items)
  end
  def submit
    @runing = true
    @wating = 20
  end
  def update
    if @runing == false
      return
    end
    flag = true
    for item in @actions
      if !item.is_completed?
        item.update
        flag = false
        if (item.is_block and !item.is_completed?)
          break
        end
      end
    end
    if flag
      if @wating > 0
        @wating -= 1
        return
      end
      @runing = false
      @actions.clear
    end
  end
  def add_animation_action(actor, animation_id)
    action = Action_Bit.new(actor, 1).set_detail(animation_id).set_block
    add_action(action)
  end
  def add_recoverhp_action(actor, value)
    action = Action_Bit.new(actor, 3).set_detail(value)
    add_action(action)
  end
end
